package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("adminCategoryController")
@RequestMapping("/admin/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    /*
    * 分页查询
    *
    * */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public Result page(CategoryPageQueryDTO categoryPageQueryDTO){
    log.info("分页查询：{}",categoryPageQueryDTO);
    return categoryService.page(categoryPageQueryDTO);
}
    //分类查询
    @GetMapping("/list")
    @ApiOperation(value = "分类查询")
    public Result list(Integer type){

        return categoryService.list(type);
    }
    //新增分类
    @PostMapping
    @ApiOperation(value = "新增分类")
    public Result add(@RequestBody CategoryDTO categoryDTO){
        log.info("新增分类：{}",categoryDTO);
        return categoryService.add(categoryDTO);
    }
    //修改启用类型
    @PostMapping("/status/{status}")
    @ApiOperation(value = "修改启用类型")
    public Result updatestatus(@PathVariable Integer status,Long id){
        log.info("修改启用类型：{}",status);
        return categoryService.updatestatus(status,id);
    }
    //修改
    @PutMapping
    @ApiOperation(value = "修改分类")
    public Result update(@RequestBody CategoryDTO categoryDTO){
        log.info("新增分类：{}",categoryDTO);
        return categoryService.update(categoryDTO);
    }
    //删除
    @DeleteMapping
    @ApiOperation(value = "删除")
    public Result date(Long id){
        log.info("删除id：{}",id);
        return categoryService.date(id);
    }
}
